home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / NCSA / tn3270 2.4d7 source / tn3270 / genattn.c < prev    next >
C/C++ Source or Header  |  1992-04-17  |  9KB  |  354 lines

  1. /*
  2.  *  tn3270 for the Macintosh Source Code
  3.  *  Brown University Computing and Information Services
  4.  *  Version 2.4d7  April, 1992
  5.  *  Copyright (c) 1988, 1989, 1990, 1991, 1992 by Brown University and by
  6.  *  Peter John DiCamillo.
  7.  *
  8.  *  Permission is granted to any individual or institution to use, copy,
  9.  *  or redistribute the binary version of this software and its
  10.  *  documentation provided this notice and the copyright notices are
  11.  *  retained.  Permission is granted to any individual or non-profit
  12.  *  institution to use, copy, modify, or redistribute the source files
  13.  *  of this software provided this notice and the copyright notices are
  14.  *  retained.  This software may not be distributed for profit, either
  15.  *  in original form or in derivative works, nor can the source be
  16.  *  distributed to other than an individual or a non-profit institution.
  17.  *  Any  individual or group interested in seeing and/or using these
  18.  *  source files but who are prevented from doing so by the above
  19.  *  constraints should contact Don Wolfe, Assistant Vice-President for
  20.  *  Computer Systems at Brown University, (401) 863-7250, for possible
  21.  *  software licensing of the source developed at Brown.
  22.  *
  23.  *  Brown University and Peter John DiCamillo make no representations
  24.  *  about the suitability of this software for any purpose.
  25.  *
  26.  *  BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
  27.  *  EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
  28.  *  INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
  29.  *  WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
  30.  *
  31.  */
  32.  
  33. #include "maclib.h"
  34.  
  35. #define fileMenu    256
  36. #define FILEID        "attnmap.r.new"
  37.  
  38. char done;                /* flag for mainline to return */
  39.  
  40. struct Rect screenRect, dragRect, pRect, sizeRect;
  41. struct WindowRecord wRecord;
  42. struct GrafPort *myWindow;
  43. MenuHandle myMenus[1];
  44.  
  45. unsigned char * name1[32] =
  46.     {"PF1", "PF2", "PF3", "PF4", "PF5", "PF6",
  47.      "PF7", "PF8", "PF9", "PF10", "PF11", "PF12",
  48.      "PF13", "PF14", "PF15", "PF16", "PF17",
  49.      "PF18", "PF19", "PF20", "PF21", "PF22",
  50.      "PF23", "PF24", "Sys", "Clear", "PA1",
  51.      "PA2", "Erase", "Insert", "Delete", "Insert"};
  52. unsigned char * name2[32] =
  53.     {"", "", "", "", "", "", "", "",
  54.      "", "", "", "", "", "", "", "",
  55.      "", "", "", "", "", "", "", "",
  56.      "Req", "", "", "", "EOF", "Mode",
  57.      "Char", "Char"};
  58.  
  59. void macinit(void);
  60. void hndmac(void);
  61. void docommand(long mResult);
  62. void defattn(char save);
  63. void addtext(Rect *key, unsigned char *name1, unsigned char *name2);
  64.  
  65. main()
  66. {
  67. macinit();                /* general Mac initialization */
  68. defattn(0);
  69. done = 0;
  70. while (!done) hndmac();
  71. }
  72.  
  73. void macinit(void)
  74. {
  75.  
  76.             /* set-up general Macintosh environment */
  77. InitGraf(&qd.thePort);
  78. InitWindows();
  79. InitFonts();
  80. InitMenus();
  81. InitDialogs(0L);
  82. InitCursor();
  83.  
  84. myMenus[0] = NewMenu(fileMenu, "\pFile");
  85. AppendMenu(myMenus[0], "\pSave");
  86. AppendMenu(myMenus[0], "\pQuit");
  87. InsertMenu(myMenus[0], 0);
  88. DrawMenuBar();
  89.  
  90. screenRect = qd.screenBits.bounds;
  91. SetRect(&dragRect, 4, 24, screenRect.right-4, screenRect.bottom-4);
  92.  
  93. pRect.top = 23;
  94. pRect.left = 5;
  95. pRect.bottom = 337;
  96. pRect.right = 505;
  97.  
  98. sizeRect.top = 25;
  99. sizeRect.left = 25;
  100. sizeRect.bottom = 296;
  101. sizeRect.right = 501;
  102.  
  103. myWindow = NewWindow(&wRecord, &pRect, "\pgenattn",
  104.             true, 3, (WindowPtr)-1L, 0, 0L);
  105. SetPort(myWindow);
  106. pRect = qd.thePort->portRect;
  107. }
  108.  
  109. void hndmac(void)
  110. {
  111.     short code;
  112.     unsigned short w, h;
  113.     long l;
  114.     struct EventRecord myEvent;
  115.     struct GrafPort *whichWindow;
  116.  
  117.     /* handle system events */
  118.         SystemTask();
  119.         if (!GetNextEvent(everyEvent, &myEvent)) return;
  120.         switch(myEvent.what) {
  121.         case mouseDown:
  122.             code = FindWindow(myEvent.where, &whichWindow);
  123.             switch (code) {
  124.             case inMenuBar:
  125.                 docommand(MenuSelect(myEvent.where));
  126.                 break;
  127.             case inSysWindow:
  128.                 SystemClick(&myEvent, whichWindow);
  129.                 break;
  130.             case inDrag:
  131.                 DragWindow(whichWindow, myEvent.where, &dragRect);
  132.                 break;
  133.             case inGrow:
  134.                 if (whichWindow == FrontWindow()) {
  135.                     l = GrowWindow(whichWindow, myEvent.where,
  136.                                 &sizeRect);
  137.                     h = l >> 16;
  138.                     w = l & 0x0000ffffL;
  139.                     SizeWindow(whichWindow, w, h, true);
  140.                     }
  141.                 break;
  142.             case inContent:
  143.                 if (whichWindow != FrontWindow()) {
  144.                     SelectWindow(whichWindow);
  145.                     }
  146.                 break;
  147.             }
  148.             break;
  149.  
  150.         case mouseUp:
  151.             break;
  152.  
  153.         case keyDown:
  154.         case autoKey:
  155.             break;
  156.  
  157.         case activateEvt:
  158.             break;
  159.  
  160.         case updateEvt:
  161.             BeginUpdate((WindowPtr)myEvent.message);
  162.             EndUpdate((WindowPtr)myEvent.message);
  163.             break;
  164.  
  165.         default:    break;
  166.         }
  167. }
  168.  
  169. void docommand(long mResult)
  170. {
  171.     short theItem, theMenu;
  172.  
  173.     theMenu = mResult >> 16;
  174.     theItem = mResult;
  175.     switch(theMenu) {
  176.         case fileMenu:
  177.             switch (theItem) {
  178.                 case 1: defattn(1);
  179.                         done = 1;
  180.                         break;
  181.                 case 2: done = 1;
  182.                         break;
  183.                 default:
  184.                         break;
  185.                 }
  186.             break;
  187.         default:
  188.             break;
  189.         }
  190.         HiliteMenu(0);
  191. }
  192.  
  193. void defattn(char save)
  194. {
  195. Rect mr;
  196. Rect keyrect;
  197. Rect framerect;
  198. short i, j;
  199. short fd, keynum;
  200. unsigned char hexline[120];
  201. unsigned char hexline2[120];
  202. BitMap menumap;
  203. GrafPtr currport;
  204. unsigned char * bitptr;
  205.  
  206. mr.top = 40;
  207. mr.left = 66;
  208. mr.bottom = mr.top + 101;
  209. mr.right = mr.left + 343; 
  210.  
  211. /* entire menu (done by menu manager) */
  212. framerect.top = mr.top - 1;
  213. framerect.left = mr.left - 1;
  214. framerect.bottom = mr.bottom + 1;
  215. framerect.right = mr.right + 1;
  216. FrameRect(&framerect);
  217.  
  218. /* pf1-12 */
  219. framerect.top = mr.top + 1;
  220. framerect.left = mr.left + 1;
  221. framerect.bottom = mr.bottom - 1;
  222. framerect.right = mr.left + 127;
  223. FrameRect(&framerect);
  224.  
  225. keynum = 0;
  226. keyrect.top = mr.top + 3;
  227. keyrect.bottom = keyrect.top + 23;
  228. for (i = 0; i < 4; i++) {
  229.     keyrect.left = mr.left + 3;
  230.     keyrect.right = keyrect.left + 40;
  231.     for (j=0; j < 3; j++) {
  232.         FrameRect(&keyrect);
  233.         addtext(&keyrect, name1[keynum], name2[keynum]);
  234.         keynum++;
  235.         keyrect.left += 41;
  236.         keyrect.right += 41;
  237.         }
  238.     keyrect.top += 24;
  239.     keyrect.bottom += 24;
  240.     }
  241.  
  242. /* pf13-24 */
  243. framerect.top = mr.top + 1;
  244. framerect.left = mr.left + 216;
  245. framerect.bottom = mr.bottom - 1;
  246. framerect.right = mr.left + 342;
  247. FrameRect(&framerect);
  248. keyrect.top = mr.top + 3;
  249. keyrect.bottom = keyrect.top + 23;
  250. for (i = 0; i < 4; i++) {
  251.     keyrect.left = mr.left + 218;
  252.     keyrect.right = keyrect.left + 40;
  253.     for (j=0; j < 3; j++) {
  254.         FrameRect(&keyrect);
  255.         addtext(&keyrect, name1[keynum], name2[keynum]);
  256.         keynum++;
  257.         keyrect.left += 41;
  258.         keyrect.right += 41;
  259.         }
  260.     keyrect.top += 24;
  261.     keyrect.bottom += 24;
  262.     }
  263.  
  264. /* special keys */
  265. framerect.top = mr.top + 1;
  266. framerect.left = mr.left + 129;
  267. framerect.bottom = mr.bottom - 1;
  268. framerect.right = mr.left + 214;
  269. FrameRect(&framerect);
  270. keyrect.top = mr.top + 3;
  271. keyrect.bottom = keyrect.top + 23;
  272. for (i = 0; i < 4; i++) {
  273.     keyrect.left = mr.left + 131;
  274.     keyrect.right = keyrect.left + 40;
  275.     for (j=0; j < 2; j++) {
  276.         FrameRect(&keyrect);
  277.         addtext(&keyrect, name1[keynum], name2[keynum]);
  278.         keynum++;
  279.         keyrect.left += 41;
  280.         keyrect.right += 41;
  281.         }
  282.     keyrect.top += 24;
  283.     keyrect.bottom += 24;
  284.     }
  285.  
  286. if (save == 0) return;
  287.  
  288. bitptr = (unsigned char *)NewPtr(4448L);
  289. menumap.baseAddr = (Ptr)bitptr;
  290. for (i=0; i < 4448; i++) *(bitptr + i) = 0;
  291. menumap.rowBytes = 44;
  292. menumap.bounds.top = 0;
  293. menumap.bounds.left = 0;
  294. menumap.bounds.bottom = mr.bottom - mr.top;
  295. menumap.bounds.right = mr.right - mr.left;
  296. GetPort(&currport);
  297. CopyBits(&(currport->portBits), &menumap, &mr, &(menumap.bounds),
  298.         srcCopy, 0L);
  299. fd = open(FILEID, O_CREAT+O_WRONLY);
  300. write(fd, "data 'MMAP' (256, preload) {\n", 29);
  301. for (i=0; i < 4448; i+= 16) {
  302.     sprintf(hexline, "\t$\"%02x%02x %02x%02x %02x%02x %02x%02x",
  303.             *(bitptr+i), *(bitptr+i+1),
  304.             *(bitptr+i+2), *(bitptr+i+3),
  305.             *(bitptr+i+4), *(bitptr+i+5),
  306.             *(bitptr+i+6), *(bitptr+i+7));
  307.     sprintf(hexline2, " %02x%02x %02x%02x %02x%02x %02x%02x\"\n",
  308.             *(bitptr+i+8), *(bitptr+i+9),
  309.             *(bitptr+i+10), *(bitptr+i+11),
  310.             *(bitptr+i+12), *(bitptr+i+13),
  311.             *(bitptr+i+14), *(bitptr+i+15));
  312.     strcat(hexline, hexline2);
  313.     for (j=0; j < strlen(hexline); j++) {
  314.         hexline[j] = toupper(hexline[j]);
  315.         }
  316.     write(fd, hexline, strlen(hexline));
  317.     }
  318. write(fd, "};\n", 3);
  319. close(fd);
  320. DisposPtr(bitptr);
  321. }
  322.  
  323. void addtext(Rect *key, unsigned char *name1, unsigned char *name2)
  324. {
  325. short w;
  326.  
  327. TextFont(3);
  328. c2pstr(name1);
  329. c2pstr(name2);
  330. if (name2[0] == 0) {
  331.     TextSize(12);
  332.     w = StringWidth(name1);
  333.     if (w > 38) w = 38;
  334.     w = (38-w)/2;
  335.     MoveTo((*key).left+w+1, (*key).bottom-7);
  336.     DrawString(name1);
  337.     }
  338. else {
  339.     TextSize(9);
  340.     w = StringWidth(name1);
  341.     if (w > 38) w = 38;
  342.     w = (38-w)/2;
  343.     MoveTo((*key).left+w+1, (*key).bottom-13);
  344.     DrawString(name1);
  345.     w = StringWidth(name2);
  346.     if (w > 38) w = 38;
  347.     w = (38-w)/2;
  348.     MoveTo((*key).left+w+1, (*key).bottom-4);
  349.     DrawString(name2);
  350.     }
  351. p2cstr(name1);
  352. p2cstr(name2);
  353. }
  354.